package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.admin.service.impl.AdChannelServiceImpl;
import com.usian.apis.admin.AdChannelCollectionApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("api/v1/channel")
@RestController
@Api(value = "频道管理",tags = "channel",description = "频道管理Api")
public class AdChannelCollection implements AdChannelCollectionApi {
    @Autowired
    private AdChannelServiceImpl adChannelService;
    @Override
    @PostMapping("/list")
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询")
    @ApiImplicitParam(name = "dto",type = "ChannelDto",value = "查询名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    @Override
    @PostMapping("/save")
    @ApiOperation(value = "新增频道信息")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "新增频道")
    public ResponseResult inster(@RequestBody AdChannel adChannel) {
        return adChannelService.inster(adChannel);
    }

    @Override
    @PostMapping("/update")
    @ApiOperation(value = "修改频道信息")
    @ApiImplicitParam(name = "adChannel",type = "AdChannel",value = "修改频道")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @Override
    @GetMapping("del{id}")
    @ApiOperation(value = "删除频道信息")
    @ApiImplicitParam(name = "id",type = "Integer",value = "删除频道")
    public ResponseResult del(@PathVariable Integer id) {
        return adChannelService.del(id);
    }

    @Override
    @GetMapping("/findAll")
    public ResponseResult findAll() {
        List<AdChannel> adChannelList = adChannelService.list();
        return ResponseResult.okResult(adChannelList);
    }
}
